package com.twu.biblioteca;

import java.util.List;

public class UserList {
    private final List<User> users;
    private User loggedInUser;
    private boolean loginSet = false;

    public UserList(List<User> users) {
        this.users = users;
    }

    public boolean isLoggedIn(User user) {
        return users.contains(user);
    }

    public boolean setLoggedInUser(User user) {
        if (isLoggedIn(user)) {
            final int index = users.lastIndexOf(user);
            loggedInUser = users.get(index);
            loginSet = true;
            return true;
        }
        return false;
    }

    public User getLoggedInUser() {
        return loggedInUser;
    }

    public boolean isLoginSet() {
        return loginSet;
    }
}
